<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
if(!isset($_SESSION['memberid']) && !isset($_SESSION['custid'])!="") {
	header("location:customerlogin.php");
	die();
}
// check customer basket is empty or not
$id=$_SESSION['memberid'];
if(isset($_SESSION['memberid']) && trim($_SESSION['memberid']!="")) {
	$id = $_SESSION['memberid'];
	$sqlbask="select * from tblcustomerbaskets where intcustomerid='$id'";
	$resbask=$n02586916_db->select($sqlbask);
	if(count($resbask)==0) {
		header("location:customerlogin.php");
		die();
	}
} else if(isset($_SESSION['custid']) && ($_SESSION['custid'])!="") {
$id= $_SESSION['custid'];
$sqlbask="select * from tblcustomerbaskets where intcustomerid='$id'";
$resbask=$n02586916_db->select($sqlbask);
	if(count($resbask)==0) {
		header("location:customerlogin.php");
		die();
	}
}

if(isset($_SESSION['memberid']) && ($_SESSION['memberid'])!="") {
	$userid=$_SESSION['memberid'];
} else if(isset($_SESSION['custid']) && ($_SESSION['custid'])!="") {
	$userid= $_SESSION['custid'];
}

if(isset($_REQUEST['ship']) && ($_REQUEST['ship'])!="")	{
	$ship=$_REQUEST['ship'];
}

?>
<?php include("inc/head.inc.php");?>
<script language="javascript">
function check()
{
	var cond=true;
	if(document.code.dcode.value.length==0)
	{
		alert("Please enter Code.");
		if(cond==true)
		{
			document.code.dcode.focus();
		}
		cond=false;
		return false;
	}	
}	
</script>
<body>
<table width="824" border="0" cellpadding="0" cellspacing="0"  align="center">
  
  <tr>
    <td class="headerclass"><?php include(INC."top.inc.php") ?></td>
  </tr>
  <tr>
    <td valign="top" class="maincontainer"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr><td valign="top"class="leftmenuback"><?php include(INC."left.inc.php") ?></td>
        <td valign="top">
		<table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
        <tr>
          <td width="100%" height="23" class="head">
		  <div class="pageheader">Final Discounts</div>
		  </td>
        </tr>
		  <tr>
		   <td height="23" align="right" valign="middle" class="staus"><img src="images/back.gif" onClick="history.go(-1);" border="0"/></td>
	    </tr>
		 <tr>
           <td height="23" valign="middle" class="font">&nbsp; <span class="font">&nbsp;1&nbsp;&nbsp;confirm</span> | <span class="font">&nbsp;2&nbsp;&nbsp;postage</span> | <span class="font">&nbsp;3&nbsp;&nbsp;pay</span> | <span class="price">&nbsp;5&nbsp;&nbsp;Discount Codes</span> | <span class="font">&nbsp;5&nbsp;&nbsp;Order Confirmation</span></td>
	    </tr>
        <tr>
          <td align="center">
		  <br />
		  <form name="code" method="post" action="checkfidetail.php?ship=<?php echo $ship;?>">
		  
		  <table width="100%" border="0" cellpadding="0" cellspacing="1" class="proborder">
		 
		  <tr>
			<td height="23" colspan="4" class="search" bgcolor="#E9E9E9" style="border:1px solid #999999;">&nbsp; Discount Code </td>
		  </tr>
			<?php
			if(isset($_SESSION['memberid']) && ($_SESSION['memberid'])!="") {
				$custid=$_SESSION['memberid'];
			} else if(isset($_SESSION['custid']) && ($_SESSION['custid'])!="") {
				$custid= $_SESSION['custid'];
			}
			$conddiscount=false;
		  	if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit'])== "Check Your Code")	{
				$code=mysql_real_escape_string($_REQUEST['dcode']);
				$currentdate=date("y-m-d");
				$year=date("y");
				$month=date("m");
				$day=date("d");
				$sqld="SELECT * FROM tbldiscountcode WHERE (intcusid = '$custid' OR intcusid = '0') and varcode='$code' and  (DATE_FORMAT(dtexpire,'%y')>'$year' OR DATE_FORMAT(dtexpire,'%m')>$month OR DATE_FORMAT(dtexpire,'%d')>$day)";
				$resultd=$n02586916_db->select($sqld);
				if($resultd) {
						$discode=$resultd[0]['varcode'];
						$_SESSION['discount']=$discode;
						$conddiscount=true;
				} else {
						$conddiscount=false;
						echo '<tr class="font"><td colspan="4" align="center" class="font">This is not valid code or Expired Code.</td></tr>';				
				}	
			}
			if($conddiscount==true)	{
		  ?>
		  <tr class="font">
			<td colspan="4" align="center" class="font">
		  		Your discount code has been validated and you will receive the discount provided by the code<br />
			</td>
		  </tr>
		  <?php }else{ ?>
		  <tr>
			<td width="10%">&nbsp;</td>
		    <td width="19%" class="font">Enter Your code </td>
		    <td width="24%">:		        
		      <input name="dcode" type="text" class="font" size="12" /></td>
		    <td width="47%">
		      <input name="Submit" type="submit" class="font" value="Check Your Code" onClick="return check();" />		    </td>
		  </tr> 
		  <?php }?>
		  <tr>
			<td colspan="4">&nbsp;</td>
		  </tr>
		</table>
		  
          <table width="100%" border="0" cellpadding="0" cellspacing="3" class="proborder">
            <tr>
              <td width="75%" align="left" class="msg1">Continue Checkout Procedure
                to confirm this order.</td>
              <td width="37%" align="right">
		<a href="checkfinalreview.php?ship=<?php echo $ship;?>" class="ab"><img src="images/continue.gif" border="0" /></a>
		</form>
             </td>
            </tr>
          </table>
          <br />
      <table width="100%" border="0" cellpadding="0" cellspacing="2" >
        <tr>
          <td align="center" valign="bottom" class="fontsmall">&nbsp;</td>
		  </tr>
        <tr>
          <td align="center" class="fontsmall">&nbsp;</td>
        </tr>
    </table>		  </td>
        </tr> 
    </table>		</td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td><?php include "inc/bottom.inc.php"; ?></td>
  </tr>
</table>
</body>
</html>
